using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public static GameManager Instance;
    
    [Header("游戏设置")]
    public int maxPlayers = 4;
    public float matchTime = 300f; // 5分钟
    
    [Header("UI引用")]
    public Text scoreText;
    public Text timerText;
    public GameObject gameOverPanel;
    
    private float currentMatchTime;
    private bool isGameOver;
    
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }
    
    void Start()
    {
        InitializeGame();
    }
    
    void Update()
    {
        if (!isGameOver)
        {
            UpdateMatchTimer();
        }
    }
    
    void InitializeGame()
    {
        currentMatchTime = matchTime;
        isGameOver = false;
        gameOverPanel.SetActive(false);
    }
    
    void UpdateMatchTimer()
    {
        currentMatchTime -= Time.deltaTime;
        if (currentMatchTime <= 0)
        {
            GameOver();
        }
        
        // 更新UI
        if (timerText != null)
        {
            int minutes = Mathf.FloorToInt(currentMatchTime / 60);
            int seconds = Mathf.FloorToInt(currentMatchTime % 60);
            timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
        }
    }
    
    public void GameOver()
    {
        isGameOver = true;
        gameOverPanel.SetActive(true);
    }
} 